<?php
$this->pageTitle = Yii::app()->name . ' - ' . Yii::t('home', 'register');
$this->breadcrumbs = array(
    Yii::t('home', 'register')
);

$baseUrl = Yii::app()->request->baseUrl;
$extScript = Yii::app()->clientScript;
$extScript->registerScriptFile($baseUrl . '/js/CryptoJS-v3.1.2/rollups/md5.js');
?>

<div id="focus" class="wrapper row100 bgded" style="background-image:url('images/live-demo/background-03.jpg');">
    <div class="overlay">
        <div id="newsletter" class="clear center">
            <h2 class="uppercase font-x3 btmspace-50"><?= Yii::t('register', 'welcome') ?></h2>

            <div class="form">
                <?php
                $form = $this->beginWidget('CActiveForm', array(
                    'id' => 'register-form',
                    'enableClientValidation' => true,
                    'clientOptions' => array(
                        'validateOnSubmit' => true,
                        'afterValidate' => "js:function(form, data, hasError) {
                if (!hasError) {
                    form[0][1].value = CryptoJS.MD5(form[0][1].value);
                    form[0][2].value = CryptoJS.MD5(form[0][2].value);
                    return true;
                }
                return false;
            }"
                    ),
                    'focus' => array($model, 'username'),
                    'htmlOptions' => array(
                        'enctype' => 'multipart/form-data'
                    )
                ));
                ?>

                <div class="row">
                    <?php echo $form->textField($model, 'username', array('placeholder' => Yii::t('register', 'email'))); ?>
                    <?php echo $form->error($model, 'username'); ?>
                </div>

                <div class="row">
                    <?php echo $form->passwordField($model, 'password', array('placeholder' => Yii::t('register', 'password'), 'autocomplete' => 'off', 'value' => '')); ?>
                    <?php echo $form->error($model, 'password'); ?>
                </div>

                <div class="row">
                    <?php echo $form->passwordField($model, 'repassword', array('placeholder' => Yii::t('register', 'repassword'), 'autocomplete' => 'off', 'value' => '')); ?>
                    <?php echo $form->error($model, 'repassword'); ?>
                </div>

                <div class="row">
                    <?php echo $form->textField($model, 'firstname', array('placeholder' => Yii::t('register', 'firstname'))); ?>
                    <?php echo $form->error($model, 'firstname'); ?>
                </div>

                <div class="row">
                    <?php echo $form->textField($model, 'lastname', array('placeholder' => Yii::t('register', 'lastname'))); ?>
                    <?php echo $form->error($model, 'lastname'); ?>
                </div>

                <div class="row" style="display: none;">
                    <?php echo $form->textField($model, 'height', array('placeholder' => Yii::t('register', 'height'))); ?>
                    <?php echo $form->error($model, 'height'); ?>
                </div>

                <div class="row" style="display: none;">
                    <?php echo $form->textField($model, 'weight', array('placeholder' => Yii::t('register', 'weight'))); ?>
                    <?php echo $form->error($model, 'weight'); ?>
                </div>

                <div class="row">
                    <?php echo $form->dropDownList($model, 'gender', array('' => Yii::t('register', 'gender'), '1' => Yii::t('register', 'male'), '2' => Yii::t('register', 'female'))); ?>
                    <?php echo $form->error($model, 'gender'); ?>
                </div>

                <div class="row">
                    <?php
                    $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                        'attribute' => 'birthday',
                        'model' => $model,
                        'name' => 'birthday',
                        'options' => array(
                            'defaultDate' => date('Y-m-d'),
                            'showButtonPanel' => false,
                            'showAnim' => 'slide',
                            'dateFormat' => 'yy-mm-dd',
                            'dayNamesMin' => Yii::t('register', 'short_days'),
                            'monthNamesShort' => Yii::t('register', 'months'),
                            'changeMonth' => true,
                            'changeYear' => true,
                            'yearRange' => '1900:2099',
                            'beforeShow' => 'js:function(){  
                    if($(this).val() != ""){
                        var arrayDate = $(this).val().split("-");  
                        if (parseInt(arrayDate[0]) > 2400) {
                            arrayDate[0] = parseInt(arrayDate[0]) - 543;
                        }
                        $(this).val(arrayDate[0] + "-" + arrayDate[1] + "-" + arrayDate[2]);
                    }
                    setTimeout(function(){
                        $.each($(".ui-datepicker-year option"), function(j, k){
                            var textYear = "";
                            if(parseInt($(".ui-datepicker-year option").eq(j).val()) < 2400){
                                textYear = parseInt($(".ui-datepicker-year option").eq(j).val()) + 543;
                            }
                            $(".ui-datepicker-year option").eq(j).text(textYear);
                        });             
                    },50);
                }',
                            'afterRender' => 'js:function(){  
                    alert("sss");
                }',
                            'onClose' => 'js:function(){
                    if($(this).val() != "" && $(this).val() == dateBefore){         
                        var arrayDate = dateBefore.split("-");
                        if (parseInt(arrayDate[0]) < 2400) {
                            arrayDate[0] = parseInt(arrayDate[0]) + 543;
                        }
                        $(this).val(arrayDate[0] + "-" + arrayDate[1] + "-" + arrayDate[2]);    
                    }       
                }',
                            'onSelect' => 'js:function(dateText, inst){ 
                    dateBefore = $(this).val();
                    var arrayDate = dateText.split("-");
                    if (parseInt(arrayDate[0]) < 2400) {
                        arrayDate[0] = parseInt(arrayDate[0]) + 543;
                    }
                    $(this).val(arrayDate[0] + "-" + arrayDate[1] + "-" + arrayDate[2]);
                }',
                        ),
                        'htmlOptions' => array(
//                            'value' => (date('Y') + 543) . date('-m-d'),
                            'onFocus' => 'this.value = ""',
                            'placeholder' => Yii::t('register', 'birthday')
                        ),
                    ));
                    ?>
                    <?php echo $form->error($model, 'birthday'); ?>
                </div>

                <div class="row">
                    <?php
                    $this->widget('application.extensions.timepicker.EJuiDateTimePicker', array(
                        'model' => $model,
                        'name' => 'time_of_birthday',
                        'options' => array(
                            'showOn' => 'focus',
                            'timeFormat' => 'hh:mm',
                            'timeOnly' => true,
                        ),
                        'htmlOptions' => array(
                            'maxlength' => '10', // textField maxlength
                            'placeholder' => Yii::t('register', 'time_of_birthday')
                        ),
                    ));
                    ?>
                    <?php echo $form->error($model, 'time_of_birthday'); ?>
                </div>

                <div class="row">
                    <?php echo $form->textField($model, 'mobilephone', array('placeholder' => Yii::t('register', 'mobilephone'))); ?>
                    <?php echo $form->error($model, 'mobilephone'); ?>
                </div>
                <div class="row">
                    <? echo Yii::t('admin', 'picture') ?>
                </div>
                <div class="row">
                    <?php echo $form->fileField($model, 'profile_image'); ?>
                    <?php echo $form->error($model, 'profile_image'); ?>
                </div>

                <div class="row buttons">
                    <?php echo CHtml::tag('button', array('class' => 'btn', 'type' => 'submit'), Yii::t('register', 'register')); ?>
                </div>
                
                <?php echo CHtml::link(Yii::t('login', 'login'), array('login/index')); ?>

                <?php $this->endWidget(); ?>
            </div><!-- form -->
        </div>
    </div>
</div>